package com.smile.ye.common.security;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.smile.ye.data.entity.UserEntity;
import com.smile.ye.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
@Component
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    UserMapper accountMapper;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        LambdaQueryWrapper<UserEntity> wrapper = new LambdaQueryWrapper();
        wrapper.eq(UserEntity::getUsername,username);
        UserEntity user = accountMapper.selectOne(wrapper);
        if(user == null) throw new RuntimeException("账号不存在");
//        ArrayList<RoleEntity> roleList = userMapper.getUserRole(user.getId());
        UserDetailsImpl userDetails = new UserDetailsImpl();
        userDetails.setUser(user);
//        userDetails.setRoles(roleList);
        return userDetails;
    }
}
